﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.mMall.Seller
{
	public partial class mfModifyOrder : msBsc.Cls.mBPDealer
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}
        private void getOrder()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizDJkOrdersDetail orderInfo = new AppLogic.DataAlc.CBizDJkOrdersDetail())
            {
                DataSet ds = orderInfo.GetOrderDetailsById(orderId,true);
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "ORDERS_INFO_ID,ORDER_TIME,ORDER_CODE,ORDER_STATUS,ORDER_START_TIME,ORDER_STOP_TIME,ORDER_TOTAL_BALANCE,DISCOUNT_AMT,PAID_AMT,CUSTOMER_REGISTER_ID,CUSTOMER_NICK,CUSTOMER_DEFAULT_PIC,DEPOSIT_RATIO,PAYABLE_AMT,PAYABLE_TOTAL_AMT", 1, 100, "");
                this.ExecJScript("setOrder(" + ret + ")");
            }
        }

        private void modifyPrice()
        {
            string orderId = this.GetParamHtValue("orderId");
            if (string.IsNullOrEmpty(orderId))
            {
                this.Alert("请选择要修改的订单");
                return;
            }
            string djackId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(djackId))
            {
                this.Alert("请先登录");
                return;
            }
            string orderList = this.GetParamHtValue("orderList");
            if (string.IsNullOrEmpty(orderList))
            {
                this.Alert("请选择修改的内容");
                return;
            }
            string bili = this.GetParamHtValue("bili");
            decimal ratio = 0.2M;
            if (bili.Trim() == "0.5")
            {
                ratio = 0.5M;
            }

            using (msBsc.AppLogic.DataAlc.CBizDJkOrdersDetail orderDetail = new AppLogic.DataAlc.CBizDJkOrdersDetail())
            {
                string[] ret = orderDetail.UpdateDetailPrice(orderId, djackId, orderList, ratio);
                if (ret[0] != "true")
                {
                    this.Alert(ret[1]);
                }
                else {
                    this.ExecJScript(@"window.location.href = ""/ms_OrderInfo.htm?orderId="+orderId+@"""");
                }
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                getOrder();
            }
            else if (this.strAction=="modifyOrder")
            {
                modifyPrice();
            }
        }
	}
}